/** @file bt_main.c
  *  
  * @brief This file contains the driver interface functions and DLL entry
  * function of Bluetooth driver. It includes init, exit, open, close and 
  * control functions etc..
  * 
  * (c) Copyright 2003-2007, Marvell International Ltd.
  * All Rights Reserved
  */

#include <windows.h>
#include <ceddk.h>

#include "bt_def.h"
#include "bt_dev.h"
#include "bt_func.h"


/********************************************************
        Local Variables
********************************************************/

/********************************************************
        Global Variables
********************************************************/
extern PMRVDRV_ADAPTER Adapter;

/********************************************************
        Local Functions
********************************************************/

/********************************************************
        Global Functions
********************************************************/

BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) 
{
    BOOL fRetVal = TRUE;
    
    switch (dwReason)
    {
        case DLL_PROCESS_ATTACH:
            RETAILMSG(1, (L"[MRVL-BT]:DLL_PROCESS_ATTACH\n\r"));
            DisableThreadLibraryCalls((HMODULE) hinstDLL);
            if (!SDInitializeCardLib())
            {
                fRetVal = FALSE;
                break;
            }
            break;
            
        case DLL_PROCESS_DETACH:
            RETAILMSG(1, (L"[MRVL-BT]:DLL_PROCESS_DETACH\n\r"));
            SDDeinitializeCardLib();
            break;
    }

    return fRetVal;
}

/*
 * This function is called by the SDHC when the BT device is inserted.
 */
///////////////////////////////////////////////////////////////////////////////
//  BSD_Init - the init entry point for stream driver
//  Input:  dwContext - the context for this init
//  Output: 
//  Return: returns a non-zero context
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
DWORD BSD_Init(DWORD dwContext)
{
    DWORD           pInstance;      // this instance of the device
    MRVL_STATUS     Status;

    RETAILMSG(1, (L"[MRVL-BT]:BSD_Init\n\r"));

    // Only support one device
    Status = MrvBTDrvInit(dwContext);
    if (Status != MRVL_STATUS_SUCCESS)
    {
        RETAILMSG(1, (L"[MRVL-BT]:MrvBTDrvInit Failed !\n\r"));
        return (DWORD)0;
    }

    pInstance = (DWORD)Adapter;

    return (DWORD)pInstance;
}

/*
 * This function is called by the SDHC when the BT device is ejected.
 */
///////////////////////////////////////////////////////////////////////////////
//  BSD_Deinit - the deinit entry point for stream driver
//  Input:  hDeviceContext - the context returned from BSD_Init
//  Output: 
//  Returns: always returns TRUE.  
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
BOOL BSD_Deinit(DWORD hDeviceContext)
{
    RETAILMSG(1, (L"[MRVL-BT]:BSD_Deinit\n\r"));

    MrvBTDrvDeInit(hDeviceContext);

    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
//  BSD_IOControl - the I/O control entry point for stream driver
//  Input:  hDeviceContext - the context returned from BSD_Open
//          IoctlCode - the ioctl code
//          pBufIn - the input buffer from the user
//          dwLenIn - the length of the input buffer
//          pBufOut - the output buffer from the user
//          dwLenOut - the length of the output buffer
//          pdwActualOut - the size of the transfer
//  Output: 
//  Return:  TRUE if Ioctl was handled
//  Notes:   
///////////////////////////////////////////////////////////////////////////////
BOOL BSD_IOControl(DWORD   hDeviceContext,
                   DWORD   IoctlCode,
                   PBYTE   pBufIn,
                   DWORD   dwLenIn,
                   PBYTE   pBufOut,
                   DWORD   dwLenOut,
                   PDWORD  pdwActualOut)
{
    RETAILMSG(1, (L"[MRVL-BT]:BSD_IOControl\n\r"));
    return FALSE;
}

///////////////////////////////////////////////////////////////////////////////
//  BSD_Open - the open entry point for stream driver
//  Input:  hDeviceContext - the device context from NDL_Init
//          AccessCode - the desired access
//          ShareMode - the desired share mode
//  Output: 
//  Return: returns an open context 
//  Notes:  Not used
///////////////////////////////////////////////////////////////////////////////
DWORD BSD_Open(DWORD    hDeviceContext,
               DWORD    AccessCode,
               DWORD    ShareMode)
{
    RETAILMSG(1, (L"[MRVL-BT]:BSD_Open\n\r"));
    return hDeviceContext;
}

///////////////////////////////////////////////////////////////////////////////
//  BSD_Close - the close entry point for stream driver
//  Input:  hOpenContext - the context returned from NDL_Open
//  Output: 
//  Return: always returns TRUE
//  Notes:  Not used
///////////////////////////////////////////////////////////////////////////////
BOOL BSD_Close(DWORD hOpenContext)
{
    RETAILMSG(1, (L"[MRVL-BT]:BSD_Close\n\r"));
    return TRUE;
}
